<!-- 授信申请 -->
<template>
  <div>
    <Fllow ref="fllow" />
    <SetMoney ref="SetMoney" />
    <Form ref="form"></Form>
    <ZgNewPage
      ref="page"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :extraBtns="extraBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="240"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          align="center"
          :title="h.label"
        >
          <template slot-scope="record">
            <template v-if="h.code === '1'">
              <span style="color: #1890ff; cursor: pointer" @click="getFloow(record)">{{ record[h.code] }}</span>
            </template>
            <template v-else>
              {{ record[h.code] }}
            </template>
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Fllow from './fllow'
import SetMoney from './SetMoney'
import Form from './Form'
const selectData = [
  { value: '1', label: '选项1' },
  { value: '2', label: '选项2' },
  { value: '3', label: '选线3' }
]
export default {
  components: {
    Fllow,
    SetMoney,
    Form
  },
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: true,
        showHeaderConfig: false,
        showAttachBtn: false
      },
      conditions: [
        { code: 'select', compType: '下拉选择', label: '供应链编号', defaultVal: '', extra: { 下拉选项: selectData } },
        {
          code: 'name',
          compType: '单行文本',
          label: '合同编号',
          defaultVal: '',
          extra: { placeholder: '请输入合同编号' }
        },
        {
          code: 'name',
          compType: '单行文本',
          label: '授信产品',
          defaultVal: '',
          extra: { placeholder: '请输入授信产品' }
        },
        {
          code: 'name',
          compType: '单行文本',
          label: '申请额度',
          defaultVal: '',
          extra: { placeholder: '请输入申请额度' }
        },
        { code: 'political3', compType: '字典', label: '流转状态', defaultVal: '', extra: { 字典类型: 'political' } },
        { code: 'political3', compType: '字典', label: '授信类型', defaultVal: '', extra: { 字典类型: 'political' } },
        { code: 'select', compType: '下拉选择', label: '创建人', defaultVal: '', extra: { 下拉选项: selectData } },
        { code: 'month', compType: '日期', label: '创建时间', defaultVal: '' }
      ],
      headers: [
        { code: '1', label: '流转状态', isShow: true, sort: 0 },
        { code: '2', label: '授信编号', isShow: true, sort: 0 },
        { code: '3', label: '供应链', isShow: true, sort: 0 },
        { code: '4', label: '合同编号', isShow: true, sort: 0 },
        { code: '5', label: '授信类型', isShow: true, sort: 0 },
        { code: '6', label: '申请额度', isShow: true, sort: 0 },
        { code: '7', label: '创建时间', isShow: true, sort: 0 },
        { code: '8', label: '创建人', isShow: true, sort: 0 }
      ],
      dataBtns: [
        {
          key: 1,
          name: '详情',
          type: 'link',
          isShow: () => {
            return true
          }
        },
        { key: 2, name: '编辑', type: 'link', isShow: (row) => ['暂存', '已驳回', '已撤销'].includes(row['1']) },
        { key: 3, name: '撤销', type: 'link', isShow: (row) => ['已提交'].includes(row['1']) },
        { key: 4, name: '调额', type: 'link', isShow: (row) => ['已授信'].includes(row['1']) },
        { key: 5, name: '作废', type: 'link', isShow: (row) => ['暂存', '已撤销'].includes(row['1']) }
      ],
      extraBtns: [
        { key: 1, name: '导出', icon: 'user', type: 'primary' },
        { key: 2, name: '申请', icon: 'user', type: 'primary' }
      ]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        {
          key: '1',
          id: '1',
          1: '暂存',
          2: '2025063',
          3: '供应链1',
          4: 'jkjdkiii',
          5: '产品授信',
          8: '李华',
          6: '1009032.00',
          7: '2025-01-01'
        },
        {
          key: '2',
          id: '2',
          1: '已提交',
          2: '2025063',
          3: '供应链1',
          4: 'jkjdkiii',
          5: '产品授信',
          8: '李华',
          6: '1009032.00',
          7: '2025-01-01'
        },
        {
          key: '3',
          id: '3',
          1: '已授信',
          2: '2025063',
          3: '供应链1',
          4: 'jkjdkiii',
          5: '产品授信',
          8: '李华',
          6: '1009032.00',
          7: '2025-01-01'
        },
        {
          key: '4',
          id: '4',
          1: '已驳回',
          2: '2025063',
          3: '供应链1',
          4: 'jkjdkiii',
          5: '产品授信',
          8: '李华',
          6: '1009032.00',
          7: '2025-01-01'
        },
        {
          key: '5',
          id: '5',
          1: '已作废',
          2: '2025063',
          3: '供应链1',
          4: 'jkjdkiii',
          5: '产品授信',
          8: '李华',
          6: '1009032.00',
          7: '2025-01-01'
        },
        {
          key: '6',
          id: '6',
          1: '已撤销',
          2: '2025063',
          3: '供应链1',
          4: 'jkjdkiii',
          5: '产品授信',
          8: '李华',
          6: '1009032.00',
          7: '2025-01-01'
        }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    toAdmin (opt) {
      if (opt.key === 1) {
        this.$refs.form.open('detail', opt.obj)
      } else if (opt.key === 2) {
        this.$refs.form.open('edit', opt.obj)
      } else if (opt.key === 3) {
        this.confirm(() => {
          // this.$http.post('/zg-system/attach/del', [param.obj.id], () => {
          //   this.search()
          // })
        }, '你确定撤销吗？')
      } else if (opt.key === 4) {
        this.$refs.SetMoney.open(opt.obj)
      } else if (opt.key === 5) {
        this.confirm(() => {
          // this.$http.post('/zg-system/attach/del', [param.obj.id], () => {
          //   this.search()
          // })
        }, '你确定作废吗？')
      }
    },
    toExtra (opt) {
      if (opt.key === 1) {
        alert('导出')
      } else {
        alert('申请')
      }
    },
    getFloow (row) {
      this.$refs.fllow.open(row)
    },
    onFilter (f, param) {},
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
